//
//  ChooseCityViewController.m
//  XDBaseFrameWork
//
//  Created by xindao on 14-10-3.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "ChooseCityViewController.h"
#import "CityCell.h"
@interface ChooseCityViewController ()

@end

@implementation ChooseCityViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.titleLabel.text = @"选择城市";

    dataArray = [[NSMutableArray alloc] initWithArray:@[@{@"CityName": @"北京",
                                                          @"Select":@"1"}]];

    myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, UI_MAINSCREEN_HEIGHT-UI_NAVIGATION_BAR_HEIGHT) style:UITableViewStylePlain];
    myTableView.dataSource = self;
    myTableView.delegate = self;
    myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.contentView addSubview:myTableView];

    if(self.isEnterFromFirstVC){
        self.leftBtn.hidden = YES;
    }
    if (self.isComeFromClick){
        self.leftBtn.hidden = NO;
    }

}

-(void)backPrePage
{
    if (self.isComeFromClick){
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark - TableView DataSource
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * bg = [UIView initViewRect:CGRectMake(0, 0, UI_SCREEN_WIDTH, 44) andBackGroudColor:RGBA(254, 254, 254, 1)];
    
    UILabel * label = [UILabel initLabelText:@"已开通服务城市" andRect:CGRectMake(20,0,150,44) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:RGBA(138, 138, 138, 1) andTextAlignment:NSTextAlignmentLeft];
    [bg addSubview:label];

    return bg;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString * cellIde = @"cell";
    CityCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIde];
    if (!cell) {
        cell = [[CityCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIde];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    if (!indexPath.row) {
        cell.topView.hidden = NO;

    }else{
        cell.topView.hidden = YES;
    }

    cell.nameLB.text = dataArray[indexPath.row][@"CityName"];
    if ([dataArray[indexPath.row][@"Select"] intValue]) {
        cell.redPointIV.hidden = NO;
    }else{
        cell.redPointIV.hidden = YES;
    }
    return cell;

}

#pragma mark - TableView Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.isEnterFromFirstVC||self.isComeFromClick){
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    }else{
        [self.navigationController popViewControllerAnimated:YES];    
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
